//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package atomgit_triger

import (
	"fmt"
	"testing"
)

const _PR_HOOK_DATA = `
{
  "action": "opened",
  "number": 1,
  "pull_request": {
    "_links": {
      "html": {
        "href": "https://atomgit.com/openlinksaas/test/change/1"
      }
    },
    "additions": 3,
    "base": {
      "label": "潘雷明:master",
      "ref": "master",
      "repo": {
        "allow_forking": true,
        "allow_rebase_merge": true,
        "allow_squash_merge": true,
        "archived": false,
        "clone_url": "https://atomgit.com/openlinksaas/test.git",
        "created_at": "2025-02-07T10:53:55Z",
        "default_branch": "master",
        "description": "sadfasdfasdf",
        "disabled": false,
        "fork": false,
        "forks": 1,
        "forks_count": 1,
        "full_name": "openlinksaas/test",
        "git_url": "git://atomgit.com/openlinksaas/test.git",
        "homepage": "https://atomgit.com/openlinksaas/test",
        "html_url": "https://atomgit.com/openlinksaas/test",
        "id": 37070260,
        "is_template": false,
        "language": "{\"Markdown\":\"{\\\"blank\\\":15,\\\"code\\\":19,\\\"nFiles\\\":1,\\\"comment\\\":0}\"}",
        "master_branch": "master",
        "name": "test",
        "owner": {
          "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
          "email": "panleiming@linksaas.pro",
          "html_url": "https://atomgit.com/openlinksaas",
          "id": "64fae54f49d9355e7a863eb6",
          "login": "openlinksaas",
          "name": "潘雷明",
          "type": "User"
        },
        "private": false,
        "public": true,
        "size": 0.104492,
        "ssh_url": "git@atomgit.com:openlinksaas/test.git",
        "stargazers_count": 0,
        "updated_at": "2025-02-07T12:01:00Z",
        "url": "https://atomgit.com/openlinksaas/test",
        "visibility": "public"
      },
      "sha": "9a072fc1500a0de674734e13d116b3423ff5db56",
      "user": {
        "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
        "email": "panleiming@linksaas.pro",
        "html_url": "https://atomgit.com/openlinksaas",
        "id": "64fae54f49d9355e7a863eb6",
        "login": "openlinksaas",
        "name": "潘雷明",
        "type": "User"
      }
    },
    "body": "{\"htmlValue\":\"<article class=\\\"4ever-article\\\"><p style=\\\"text-align:left;text-indent:0;margin-left:0\\\"><span>12313123123</span></p></article>\",\"jsonMLValue\":[\"root\",{},[\"p\",{},[\"span\",{\"data-type\":\"text\"},[\"span\",{\"data-type\":\"leaf\"},\"12313123123\"]]]]}",
    "changed_files": 1,
    "comments": 0,
    "commits": 1,
    "created_at": "2025-02-07T12:00:59Z",
    "deletions": 1,
    "diff_url": "https://atomgit.com/openlinksaas/test/change/1/diffs",
    "head": {
      "label": "OpenLinkSaas:master",
      "ref": "master",
      "repo": {
        "allow_forking": true,
        "allow_rebase_merge": true,
        "allow_squash_merge": true,
        "archived": false,
        "clone_url": "https://atomgit.com/openlinksaas-org/test2.git",
        "created_at": "2025-02-07T12:00:03Z",
        "default_branch": "master",
        "description": "2341234",
        "disabled": false,
        "fork": true,
        "forks": 0,
        "forks_count": 0,
        "full_name": "openlinksaas-org/test2",
        "git_url": "git://atomgit.com/openlinksaas-org/test2.git",
        "homepage": "https://atomgit.com/openlinksaas-org/test2",
        "html_url": "https://atomgit.com/openlinksaas-org/test2",
        "id": 37070265,
        "is_template": false,
        "language": "{\"Markdown\":\"{\\\"blank\\\":16,\\\"code\\\":20,\\\"nFiles\\\":1,\\\"comment\\\":0}\"}",
        "master_branch": "master",
        "name": "test2",
        "organization": "OpenLinkSaas",
        "owner": {
          "html_url": "https://atomgit.com/OpenLinkSaas",
          "id": "66d18a45b68d0d879bb833c1",
          "name": "OpenLinkSaas",
          "type": "Organization"
        },
        "private": false,
        "public": true,
        "size": 0.117188,
        "ssh_url": "git@atomgit.com:openlinksaas-org/test2.git",
        "stargazers_count": 0,
        "updated_at": "2025-02-07T12:00:30Z",
        "url": "https://atomgit.com/openlinksaas-org/test2",
        "visibility": "public"
      },
      "sha": "c1c28f9a680d2f4aadb10867bc9e34b3c36579c5",
      "user": {
        "html_url": "https://atomgit.com/OpenLinkSaas",
        "id": "66d18a45b68d0d879bb833c1",
        "name": "OpenLinkSaas",
        "type": "Organization"
      }
    },
    "html_url": "https://atomgit.com/openlinksaas/test/change/1",
    "id": "4ca52c35487b433fad88864e1f231f76",
    "mergeable": true,
    "merged": false,
    "number": 1,
    "patch_url": "https://atomgit.com/openlinksaas/test/change/1/commits",
    "rebaseable": true,
    "requested_reviewers": [
      {
        "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
        "html_url": "https://atomgit.com/openlinksaas",
        "id": "64fae54f49d9355e7a863eb6",
        "login": "openlinksaas",
        "type": "User"
      }
    ],
    "review_comments": 0,
    "state": "open",
    "title": "更新 README.md",
    "updated_at": "2025-02-07T12:00:59Z",
    "user": {
      "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
      "html_url": "https://atomgit.com/openlinksaas",
      "id": "64fae54f49d9355e7a863eb6",
      "login": "openlinksaas",
      "type": "User"
    }
  },
  "repository": {
    "allow_forking": true,
    "archived": false,
    "clone_url": "https://atomgit.com/openlinksaas/test.git",
    "created_at": "2025-02-07T10:53:55Z",
    "default_branch": "master",
    "description": "sadfasdfasdf",
    "disabled": false,
    "fork": false,
    "forks": 1,
    "forks_count": 1,
    "full_name": "openlinksaas/test",
    "git_url": "git://atomgit.com/openlinksaas/test.git",
    "homepage": "https://atomgit.com/openlinksaas/test",
    "html_url": "https://atomgit.com/openlinksaas/test",
    "id": 37070260,
    "is_template": false,
    "language": "{\"Markdown\":\"{\\\"blank\\\":15,\\\"code\\\":19,\\\"nFiles\\\":1,\\\"comment\\\":0}\"}",
    "master_branch": "master",
    "name": "test",
    "owner": {
      "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
      "email": "panleiming@linksaas.pro",
      "html_url": "https://atomgit.com/openlinksaas",
      "id": "64fae54f49d9355e7a863eb6",
      "login": "openlinksaas",
      "name": "潘雷明",
      "type": "User"
    },
    "private": false,
    "size": 0.104492,
    "ssh_url": "git@atomgit.com:openlinksaas/test.git",
    "stargazers_count": 0,
    "updated_at": "2025-02-07T11:59:43Z",
    "url": "https://atomgit.com/openlinksaas/test",
    "visibility": "public"
  },
  "sender": {
    "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
    "html_url": "https://atomgit.com/openlinksaas",
    "id": "64fae54f49d9355e7a863eb6",
    "login": "openlinksaas",
    "type": "User"
  }
}
`

func TestExtractPrHookAttr(t *testing.T) {
	attrList, err := ExtractPrHookAttr([]byte(_PR_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
